"""
----案例：学生类----
编写一个学生类：
属性：姓名、性别、类别默认为people
方法：hello

----封装案例：学生类----
编写一个学生类：
属性：姓名、性别、类别默认为people
方法：hello
封装属性：年龄
增加方法：显示年龄、设置年龄
"""
# class Student:
#     category = 'people'
#
#     def __init__(self, name, age):
#         self.name = name
#         self.age = age
#
#     def hello(self):
#         print(f'大家好，我叫{self.name}')
#
#
# stu1 = Student('zhangsan', 'nan')
# print(stu1.category)
# stu1.hello()
#
# stu2 = Student('lisi', 'nan')
# stu2.hello()


'''
----案例：QQ群类----
编写一个QQ群类：
属性：群号、群名、成员、群暗号
方法：显示群号、显示群名、显示群成员、出示群暗号、添加群成员、移除群成员
'''
# class QQ:
#     def __init__(self, id, name, members, pwd):
#         self.id = id
#         self.name = name
#         self.members = members
#         self.pwd = pwd
#
#     def show_id(self):
#         print("群号：", self.id)
#
#     def show_name(self):
#         print("群名：", self.name)
#
#     def show_members(self):
#         print("群成员：", self.members)
#
#     def show_pwd(self):
#         tag = 0
#         password = input("请出示群暗号：")
#         if password == self.pwd:
#             tag = 1
#         return tag
#
#     def add_member(self):
#         tag = self.show_pwd()
#         if tag == 1:
#             newmember = input("请输入新增成员的姓名：")
#             self.members.append(newmember)
#         self.show_members()
#
#     def del_member(self):
#         msg = 0
#         tag = self.show_pwd()
#         if tag == 1:
#             del_name = input('请输入要删除的成员姓名:')
#             for member in self.members:
#                 if del_name == member:
#                     msg = 1
#                     self.members.remove(member)
#                     print(self.members)
#             if msg == 0:
#                 print('该成员不存在，请重新操作')
#             self.show_members()
#
# if __name__ == '__main__':
#     q = QQ(1, 'QQ群', ["张三", "李四", "王五"], '321')
#
#     q.show_id()
#     q.show_name()
#     q.show_members()
#     # q.show_pwd()
#     q.add_member()
#     q.del_member()


'''
----案例：银行卡类----
编写一个银行卡类：
属性：银行名称、卡号、密码、姓名、余额
方法：登录、存款、取款
'''


class Bank:

    def __init__(self, id, name, password, balance):
        self.id = id
        self.name = name
        self.password = password
        self.balance = balance

    def login(self):
        count = 0
        while True:
            tag = 0
            id = input("请输入卡号：")
            pwd = input("请输入密码：")
            if id == self.id and pwd == self.password:
                tag = 1
                print(f'登陆成功，欢迎{self.name}，当前余额为：{self.balance}')
                break
            if tag == 0:
                count += 1
                if count == 3:
                    print("该账户已被锁定！")
                    break
                else:
                    print(f"卡号或密码错误，请重新输入！还剩{3 - count}次机会")
                    continue
            else:
                break
        return tag

    def save(self):
        tag = self.login()
        if tag == 1:
            money = float(input('请输入存款金额：'))
            self.balance += money
            print(f'存款成功，当前余额为：{self.balance}')

    def out(self):
        tag = self.login()
        if tag == 1:
            money = float(input('请输入取款金额：'))
            if money <= self.balance:
                self.balance -= money
                print(f'取款成功，当前余额为：{self.balance}')
            else:
                print('余额不足！')

    def menu(self):
        print(r'----欢迎----')
        print('1.存款')
        print('2.取款')
        print('3.退出')

    def main(self):
        r = self.login()
        if r == 1:
            while True:
                self.menu()
                choice = int(input('请输入你的选择：'))
                if choice == 1:
                    self.save()
                elif choice == 2:
                    self.out()
                elif choice == 3:
                    print('退出成功')
                    break
                else:
                    print('输入有误，请重新输入')


if __name__ == '__main__':
    card = Bank('1', 'zhangsan', '123', 10000)
    card.main()
